

$(document).ready(function(){
  function is_valid_url(url)
{
     return url.match(/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/);
}
    $("#fileselect").change(function(){
      var file = $("#fileselect").val();
      $("textarea.comment_post").val('').empty();
        if(file!=""){
          $(".text_description").fadeIn();
          ///////// clear value ///////////////////
        $("textarea#textarea_embed_video").val('').empty();
        $("textarea#textarea_embed_image").val('').empty(); 
        }
    })

    //// keyup on video url ////
     $("textarea#textarea_embed_video").keyup(function(){
        if( $("textarea#textarea_embed_video").val()!=""){
             $(".text_description").fadeIn();
        }
     })

     //// keyup on imageulr ////
     $("textarea#textarea_embed_image").keyup(function(){
        if( $("textarea#textarea_embed_image").val()!=""){
             $(".text_description").fadeIn();

        }
     })

     //// focuse on video ////
     
    $('input[type="radio"]').click(function(){
      if($(this).attr("value")=="checked_upload_image"){
        /// set null to description ///
        $("textarea.comment_post").val('').empty();

        /////////// end hide container /////////////
        $(".contain_upload_image").show();
        $(".contain_embed_video").hide();
        $(".contain_emebd_image").hide();
        
        ////////// hide attribute resuls //////////
        $("#result_embed_video").hide();
        $("#result_embed_image").hide();

        ///// hide description ////
        $(".text_description").hide();

        ///////// clear value ///////////////////
        $("textarea#textarea_embed_video").val('').empty();
        $("textarea#textarea_embed_image").val('').empty();  

        //// set null to image ////
        $("#fileselect").val('').empty(); 
      }
      if($(this).attr("value")=="checked_embed_video"){
         /// set null to description ///
        $("textarea.comment_post").val('').empty();

        /////////// end hide containter //////////
        $(".contain_embed_video").show();
        $(".contain_upload_image").hide();
        $(".contain_emebd_image").hide();

        $("#result_embed_image").html('');
         ////////// hide attribute resuls //////////
        $(".oembedall-container").show(); //#result_embed_video
        $("#result_embed_image").hide();
        $("#fileselect").val('').empty();

        ///////// clear value ///////////////////
        $("textarea#textarea_embed_image").val('').empty(); 

        ///// hide description ////
        $(".text_description").hide();
      }
      if($(this).attr("value")=="checked_embed_image"){
         /// set null to description ///
        $("textarea.comment_post").val('').empty();

        //////////// end hide container ///////////
        $(".contain_emebd_image").show();
        $(".contain_upload_image").hide();
        $(".contain_embed_video").hide();

        ////////// hide attribute resuls //////////
        $("#result_embed_image").show();//#result_embed_image
        $(".oembedall-container").hide(); 
         $("#result_embed_video").html('');

        ///////// clear value ///////////////////
        $("textarea#textarea_embed_video").val('').empty(); 

        ///// hide description ////
        $(".text_description").hide();
      }
      if($(this).attr("value")=="checked_embed_text"){
         /// set null to description ///
        $("textarea.comment_post").val('').empty();
        
        //// hide all all containter ///
        $(".contain_emebd_image").hide();
        $(".contain_upload_image").hide();
        $(".contain_embed_video").hide();

         ////////// hide attribute resuls //////////
        $(".oembedall-container").hide(); 

        $("#result_embed_video").hide();
        $("#result_embed_image").hide();

        /// clear value /////
        $("textarea#textarea_embed_video").val('').empty();
        $("textarea#textarea_embed_image").val('').empty(); 

        ///// show description ////
        $(".text_description").show();
      }
    });
  });

